package org.codesketch.flamingo

class User {
	String username;
	String password;
	String role = "user"
	
    static constraints = {
		username(blank:false, nullable:false, unique:true)
		password(blank:false, nullable:false)
		role(inList: ["admin", "user"])
    }
	/*
	 * Avoid to add the admin field to the database that is needed for the isAdmin method, 
	 * because admin is not a valid field, that get GORM look into the DB for that field. 
	 */
	static transients = ['admin']
	/**
	 * Test if the current user is administrator.
	 * @return true if the current user role is administator.
	 */
	boolean isAdmin() {
		return role == "admin";
	}
	/**
	 * String representation of this user.
	 */
	String toString() {
		return "${username}, ${role}"
	};
}
